class Page1 extends egret.Sprite {


	private arr_wordGoldY;
	private arr_pY;
	private arr_pX;
	private clickSP;
	private HG: HeadGo;

	public constructor() {
		super();
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.ATS, this);


	}
	private ATS(e: egret.Event) {
		
			var delay=1400;
		




			this.arr_wordGoldY = new Array();

			var bg = new egret.Bitmap(RES.getRes("bg_png"));
			this.addChild(bg);

			for (var z = 1; z <= 10; z++) {
				var bp = new egret.Bitmap(RES.getRes("goldWord" + z + "_png"));
				switch (z) {
					case 1: bp.x = 45; bp.y = 27; break;
					case 2: bp.x = 89.5; bp.y = 0; break;
					case 3: bp.x = 135; bp.y = 280; break;
					case 4: bp.x = 241; bp.y = 184; break;
					case 5: bp.x = 40.5; bp.y = 473.5; break;
					case 6: bp.x = 100; bp.y = 389; break;
					case 7: bp.x = 223; bp.y = 655; break;
					case 8: bp.x = 107.5; bp.y = 556.5; break;
					case 9: bp.x = 45; bp.y = 881; break;
					case 10: bp.x = 182; bp.y = 902; break;
				}
				bp.x -= 10;
				this.addChild(bp);
				this.arr_wordGoldY.push(bp.y);
				if (z % 2 == 0) {
					bp.y -= 90;
				}
				else {
					bp.y += 100;
				}
				bp.alpha = 0;

				egret.Tween.get(bp).wait(delay+z * 200 - z * 10).to({ alpha: 1, y: this.arr_wordGoldY[z - 1] }, 800 - z * 10, egret.Ease.backOut);
			}

			this.arr_pY = new Array();
			this.arr_pX = new Array();
			for (var z = 1; z <= 4; z++) {
				var pic = new egret.Bitmap(RES.getRes("p" + z + "_png"));
				this.addChild(pic);
				pic.x = 402;
				pic.alpha = 0;
				switch (z) {
					case 1: pic.y = 389; break;
					case 2: pic.y = 464; break;
					case 3: pic.y = 529; break;
					case 4: pic.y = 655; break;
				}
				this.arr_pX.push(pic.x);
				this.arr_pY.push(pic.y);

				if (z == 1 || z == 2) {
					pic.y -= 50;
					egret.Tween.get(pic).wait(delay+2000 + 400 * z).to({ alpha: 1, x: this.arr_pX[z - 1], y: this.arr_pY[z - 1] }, 700, egret.Ease.cubicOut);
				}
				else {
					pic.x += (z - 4) * 60 + 30;
					egret.Tween.get(pic).wait(delay+2000 + 400 * 3).to({ alpha: 1, x: this.arr_pX[z - 1], y: this.arr_pY[z - 1] }, 600, egret.Ease.cubicOut);
				}


			}

			for (var z = 1; z <= 5; z++) {
				var pink = new egret.Bitmap(RES.getRes("pink" + z + "_png"));
				this.addChild(pink);
				pink.alpha = 0;
				pink.y = 567;
				switch (z) {
					case 5: pink.x = 402; break;
					case 4: pink.x = 438; break;
					case 3: pink.x = 494; break;
					case 2: pink.x = 535; break;
					case 1: pink.x = 588; break;
				}
				pink.x -= 50;
				egret.Tween.get(pink).wait(delay+4000 - 150 * z).to({ alpha: 1, x: pink.x + 50 }, 1000 - z * 20, egret.Ease.backInOut);
			}

			for (var z = 1; z <= 5; z++) {
				var date = new egret.Bitmap(RES.getRes("date" + z + "_png"));
				this.addChild(date);
				date.alpha = 0;
				switch (z) {
					case 1: date.x = 438; date.y = 788; break;
					case 2: date.x = 484; date.y = 806; break;
					case 3: date.x = 508; date.y = 788; break;
					case 4: date.x = 550; date.y = 790; break;
					case 5: date.x = 590; date.y = 807; break;
				}
				if (z == 2 || z == 5) {
					egret.Tween.get(date).wait(delay+4500).to({ alpha: 1 }, 600);
				}
				else {
					date.y -= 50;
					egret.Tween.get(date).wait(delay+4550 + z * 200).to({ alpha: 1, y: date.y + 50 }, 700, egret.Ease.backOut);
				}
			}

			var enter1 = new egret.Bitmap(RES.getRes("enter1_png"));
			this.addChild(enter1);
			enter1.x = 422 + enter1.width / 2; enter1.y = 930 + enter1.height / 2;
			enter1.anchorOffsetX = enter1.width / 2; enter1.anchorOffsetY = enter1.height / 2;
			enter1.alpha = 0;
			enter1.scaleX = 1.2; enter1.scaleY = 1.2;
			setTimeout(function () {
				egret.Tween.get(enter1, { loop: true }).to({ alpha: 0.5, scaleX: 0.8, scaleY: 0.8 }, 600, egret.Ease.cubicOut).to({ alpha: 1, scaleX: 1, scaleY: 1 }, 600, egret.Ease.cubicOut);
			}, delay+5500);
			egret.Tween.get(enter1).wait(delay+5000).to({ alpha: 1, scaleX: 1, scaleY: 1 }, 500);


			var enter2 = new egret.Bitmap(RES.getRes("enter2_png"));
			this.addChild(enter2);
			enter2.x = 478 + enter2.width / 2; enter2.y = 940 + enter2.height / 2;
			enter2.anchorOffsetX = enter2.width / 2; enter1.anchorOffsetY = enter2.height / 2;
			enter2.alpha = 0;
			enter2.scaleX = 1.2; enter2.scaleY = 1.2;
			setTimeout(function () {
				egret.Tween.get(enter2, { loop: true }).to({ alpha: 0.5, scaleX: 0.8, scaleY: 0.8 }, 600, egret.Ease.cubicOut).to({ alpha: 1, scaleX: 1, scaleY: 1 }, 600, egret.Ease.cubicOut);
			}, delay+5500);
			egret.Tween.get(enter2).wait(delay+5000).to({ alpha: 1, scaleX: 1, scaleY: 1 }, 500);


			this.clickSP = new egret.Shape();
			this.clickSP.graphics.beginFill(0x000000, 1);
			this.clickSP.graphics.drawRect(0, 0, 300, 150);
			this.addChild(this.clickSP);
			this.clickSP.x = 400; this.clickSP.y = 900;
			this.clickSP.alpha = 0;

			// this.clickSP.touchEnabled=true;
			var This = this;
			setTimeout(function () {
				This.clickSP.touchEnabled = true;
			}, delay+5000)
			this.clickSP.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.TB, this);
		this.HG=new HeadGo();
		this.addChild(this.HG);
		this.HG.Go();
	}
	private TB(e: TouchEvent) {
		GoEvent.msg.dispatchEvent(new GoEvent("ChangePage", "2"));
	}
	public End() {
		egret.Tween.get(this).to({ alpha: 0 }, 600, egret.Ease.cubicOut);
		this.clickSP.touchEnabled = false;
	}
}